from uiautomation import uiautomation
import os,time

class Win_test():
    # 计算器自动化测试
    def calc_test(self):
        os.system('calc.exe')  # 打开计算器

        time.sleep(2)
        wind=uiautomation.WindowControl(Name="计算器")  #定义被测对象的窗口对象
        wind.ButtonControl(Name="清除条目").Click()   #点击CE

        wind.ButtonControl(AutomationId='138').Click()  #点击8
        wind.ButtonControl(Name="乘").Click()
        wind.ButtonControl(AutomationId='137').Click()  #点击7
        wind.ButtonControl(Name="等于").Click()

        time.sleep(2)
        actural= wind.TextControl(AutomationId='158').Name
        if actural=='56':
            print('succeed')
        else:
            print('failed')

    # txt自动化测试
    def txt_test(self):
        # os.system(r'C:\Users\Administrator\Desktop\test11.txt')   #打开文档
        time.sleep(2)
        wind=uiautomation.WindowControl(Name="test11.txt - 记事本")  #定义被测对象的窗口对象
        time.sleep(1)
        wind.SendKeys("新增内容")   #输入内容
        time.sleep(1)
        wind.MenuItemControl(Name="文件(F)").Click()     #点击文件
        time.sleep(1)
        wind.MenuItemControl(Name="另存为(A)...").Click()     #点击另存为
        time.sleep(1)
        wind.ButtonControl(Name="保存(S)").Click()      #点击保存
        time.sleep(1)
        wind.ButtonControl(Name="是(Y)").Click()      #点击是

if __name__ == '__main__':
    w = Win_test()
    w.txt_test()